<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:jsf="http://xmlns.jcp.org/jsf"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:p="http://primefaces.org/ui">

    <div align="center">
        <h:form id="formReg">
            <h1><h:outputText value="Crear y Editar un Tipo de Unidad"/></h1>
            <p:panelGrid columns="2">
                <p:outputLabel value="Name:" for="name" />
                <p:inputText id="name" value="#{productController.unitType.name}" widgetVar="textname"
                             title="Name" required="true" onblur="value=value.toUpperCase()"/>
            </p:panelGrid>
            <br/><br/>
            <p:commandButton value="Guardar" update="@form,:formTabl" action="#{productController.saveOrUpdateUnitType()}"/>
        </h:form>
    </div>
    <hr/>
    <h:form id="formTabl">
        <div align="center">
            <h1><h:outputText value="Lista de Tipo de Unidad Disponibles"/></h1>
        </div>
        <p:dataTable value="#{productController.listUnitType}" var="item" emptyMessage="No existe">
            <p:column width="5">
                <p:menuButton styleClass="menubutton-for-table">  
                    <p:menuitem value="Editar" icon="ui-icon-pencil" update=":formReg" > 
                        <f:setPropertyActionListener
                            target="#{productController.unitType}"
                            value="#{item}" />
                    </p:menuitem>
                    <!--<p:menuitem value="Eliminar" icon="ui-icon-person" 
                                action="#{productController.deleteUnitType()}" update="@form">-->
                    <p:menuitem value="Eliminar" icon="ui-icon-person" update=":frmDelete:pgDeleUnitType" oncomplete="PF('deleteUnitTypeDialog').show()">
                        <f:setPropertyActionListener value="#{item}" target="#{productController.unitType}"/>
                    </p:menuitem>
                </p:menuButton>
            </p:column>
            <p:column>
                <f:facet name="header">
                    <h:outputText value="Name"/>
                </f:facet>
                <h:outputText value="#{item.name}"/>
            </p:column>
        </p:dataTable>
    </h:form>

    <h:form id="frmDelete">	
        <p:dialog header="Eliminar Tipo de Unidad" widgetVar="deleteUnitTypeDialog" id="dElimCatDlg"  
                  showEffect="fade" hideEffect="explode" modal="true">  
            <h:panelGrid id="pgDeleUnitType" columns="1" cellpadding="4" style="margin:0 auto;">  
                <h:outputText value="Estas seguro?" /> 
                    <f:facet name="footer">
                        <p:separator />
                        <p:commandButton id="btnElimCat" update=":formTabl"
                                                        value="Si" actionListener="#{productController.deleteUnitType()}"
                                                        oncomplete="PF('deleteUnitTypeDialog').hide()"/>
                        <p:commandButton id="btnElimCancelar" oncomplete="PF('deleteUnitTypeDialog').hide()" value="No" />
                    </f:facet>
            </h:panelGrid>  
         </p:dialog>
    </h:form>
    

</ui:composition>
